package com.kk.demo.java8.lambda.base02;

import java.util.function.Function;

public class LambdaUserPrintStr {

    public LambdaUserPrintStr() {
    }

    public static void main(String[] args) {

        User user1 = new User("张三", "123", 18, 180);
        User user2 = new User("李四", "123", 19, 170);
        User user3 = new User("王五", "123", 20, 190);

        LambdaUserPrintStr userPrint = new LambdaUserPrintStr();

        System.out.println(user1.printCustom(userPrint.getChinaStr(user1)));
        System.out.println(user1.printCustom(userPrint.getWestStr(user2)));
        System.out.println(user1.printCustom(userPrint.getWestStr(user3)));

    }

    /**
     * 进行中文式的打印
     * @param userinfo
     * @return
     */
    public Function<User, String> getChinaStr(User userinfo) {
        Function<User, String> out = p -> {
            StringBuilder builder = new StringBuilder();
            builder.append("User [userName=");
            builder.append(p.getUserName());
            builder.append(", passwd=");
            builder.append(p.getPasswd());
            builder.append(", age=");
            builder.append(p.getAge());
            builder.append(", hight=");
            builder.append(p.getHight());
            builder.append("]");
            return builder.toString();
        };

        return out;
    }

    /**
     * 进行西文式的打印
     * @param userinfo
     * @return
     */
    public Function<User, String> getWestStr(User userinfo) {

        Function<User, String> out = p -> {
            StringBuilder builder = new StringBuilder();
            builder.append("User [userName=");
            builder.append(p.getUserName());
            builder.append(", age=");
            builder.append(p.getAge());
            builder.append(", passwd=");
            builder.append(p.getPasswd());
            builder.append(", hight=");
            builder.append(p.getHight());
            builder.append("]");
            return builder.toString();
        };

        return out;
    }

}
